﻿using System;
using System.IO;
using System.Linq;

namespace Bootstrap.Security.DataAccess
{
    public static class TestHelper
    {
        public static string RetrieveSolutionPath()
        {
            var dirSeparator = Path.DirectorySeparatorChar;
#if NETCOREAPP2_2
            var paths = AppContext.BaseDirectory.SpanSplit($"{dirSeparator}.vs{dirSeparator}");
#else
            var paths = AppDomain.CurrentDomain.BaseDirectory.Split(new string[] { $"{dirSeparator}.vs{dirSeparator}" }, StringSplitOptions.RemoveEmptyEntries);
#endif
            return paths.Count() > 1 ? paths[0] : Path.Combine(AppContext.BaseDirectory, $"..{dirSeparator}..{dirSeparator}..{dirSeparator}..{dirSeparator}");
        }

        public static string RetrieveProjectPath(string relativePath = "UnitTestProject1")
        {
            var solutionPath = RetrieveSolutionPath();
            return Path.Combine(solutionPath, relativePath);
        }
    }
}
